package com.skdubbo.web;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.skdubbo.service.IUserService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author smark
 */
@RestController
public class OrderController {

    //url = "dubbo://localhost:12345"
    // 缓存在开发中是否要加上去？看业务看场景
    //用id查询建议用缓存，条件很多就不建议用缓存
//    @Reference(cache = "lru")//缓存

    //failover , failfast , failsafe , failback, forking
    //cluster = "failover"
    //loadbalance = "roundrobin" 负载均衡策略
    @Reference(timeout = 3000,retries = 2)//设置timeout 默认0  ，设置重连次数，服务容错
    private IUserService userService;

    @GetMapping("/hello")
    @HystrixCommand(fallbackMethod = "sayHelloErrorCallback")
    public String sayHello(String msg){
        return userService.sayHello(msg);
    }


    /**
     * 降级处理
     * @param msg
     * @return
     */
    public String sayHelloErrorCallback(String msg){
        return "客官，请稍后再试";
    }
}
